<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap 101 Template</title>
    <base th:href="${#request.getContextPath()}+'/'">
    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div id="merchant">
    <div class="panel panel-default">
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">
                商户信息管理
            </a>
        </div>
    </div>
</nav>
<div class="panel-body">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary col-md-2"  onclick="javascript:$('.modal').modal('show');">新增</button>

<!-- Modal -->
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新增商户信息</h4>
            </div>
            <div class="modal-body">

                <form>
                    <div class="form-group">
                        <label for="merchantName">商户名称</label>
                        <input type="text" class="form-control" id="merchantName" placeholder="Email">
                    </div>
                    <div class="form-group">
                        <label for="qq">QQ号码</label>
                        <input type="text" class="form-control" id="qq" placeholder="Password">
                    </div>

                    <div class="form-group">
                        <label for="wxh">微信号码</label>
                        <input type="text" class="form-control" id="wxh" placeholder="Password">
                    </div>

                    <div class="form-group">
                        <label for="lxdh">联系电话</label>
                        <input type="text" class="form-control" id="lxdh" placeholder="Password">
                    </div>

                    <div class="form-group">
                        <label for="dlzh">登录账号</label>
                        <input type="text" class="form-control" id="dlzh" placeholder="Password">
                    </div>

                    <div class="form-group">
                        <label for="dlmm">登录密码</label>
                        <input type="password" class="form-control" id="dlmm" placeholder="Password">
                    </div>

                    <div class="form-group">
                        <label for="shdj">商户等级</label>
                        <select id="shdj">
                            <option value="-1">请选择...</option>
                            <option value="0">非认证商户</option>
                            <option value="1">认证商户V1</option>
                            <option value="2">认证商户V2</option>
                        </select>
                    </div>

                    <div class="form-group">
                        <label for="sfyx">是否有效</label>
                        <div id="sfyx">
                            <input type="radio" name="state" value="1">有效 <input type="radio"  name="state" value="0">无效
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">

                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" onclick="save()">Save changes</button>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
<table class="table table-bordered">
    <thead>
    <tr>
        <th>序号</th>
        <th>状态</th>
        <th>登录账号</th>
        <th>商户名称</th>
        <th>等级</th>
        <th>QQ</th>
        <th>联系电话</th>
        <th>创建时间</th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="merchant : ${wxbCustomers}">
        <th scope="row" th:text="${merchant.customerId}">1</th>
        <td th:text="${merchant.state}">Jacob</td>
        <td th:text="${merchant.loginName}">Thornton</td>
        <td th:text="${merchant.customerName}">@fat</td>
        <td th:text="${merchant.level}">@fat</td>
        <td th:text="${merchant.qq}">@fat</td>
        <td th:text="${merchant.phone}">@fat</td>
        <td th:text="${merchant.createtime}">@fat</td>
    </tr>
    </tbody>
</table>
</div>
</div>
    </div>
</div>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="js/jquery-3.1.1.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
<script>
    function save() {
        var merchantName = $("#merchantName").val();
        var qq = $("#qq").val();
        var wxh = $("#wxh").val();
        var phone = $("#lxdh").val();
        var username = $("#dlzh").val();
        var password = $("#dlmm").val();
        var level = $("#shdj").val();
        var state = $("input[name='state']:checked").val();
        $.post("merchant/save",{customerName:merchantName,qq:qq,wxh:wxh,phone:phone,loginName:username,loginPwd:password,state:state,level:level},
        function (data) {
            if (data.code == 1){
                console.log("添加成功");
                $('#myModal').modal("hide");
                $('#merchant').load("merchant/list");
            }else {
                console.log("添加失败");
            }
        })
    }
</script>
</body>
</html>